#pragma once
#include <iostream>
#include <unordered_map>
#include <string>
#include <fstream>
#include "Log.hpp"
const std::string filename = "./dict.txt";
const std::string sep = ":";

extern Log lg;
class Init
{
public:
    Init()
    {}
    void Load()
    {
        std::ifstream ifs(filename);
        if(!ifs.is_open())
        {
            lg(Fatal, "open file err");
            exit(1);
        }
        std::string str;
        std::string part1, part2;
        while(std::getline(ifs, str))
        {
            auto pos = str.find(sep);
            if(pos == std::string::npos)
            {
                continue;
            }
            part1 = str.substr(0, pos);
            part2 = str.substr(pos + 1);
            dict_.emplace(part1, part2);
        }
        ifs.close();
    }
    void Print()
    {
        for(auto e : dict_)
        {
            std::cout << e.first << ":" << e.second << std::endl;
        }
    }
    std::string Translate(const std::string &str)
    {
        auto pos = dict_.find(str);
        if(pos == dict_.end())
            return "unknown";
        else 
            return dict_[str];
    }
private:
    std::unordered_map<std::string, std::string> dict_;
};
